import os
import zipfile


def compress_exe_files(folder_path):
    for root, dirs, files in os.walk(folder_path):
        print(f"processing {root}")
        for file in files:
            if file.endswith('setup.exe'):
                file_path = os.path.join(root, file)
                # 获取文件相对路径
                # rel_path = os.path.relpath(file_path, folder_path)
                file_name = os.path.basename(file_path)
                file_name_wo_ext = os.path.basename(os.path.splitext(file_path)[0])
                # 压缩文件
                with zipfile.ZipFile(os.path.join(root, file_name_wo_ext + '.zip'), 'w', zipfile.ZIP_DEFLATED) as zipf:
                    zipf.write(file_path, file_name)

# 替换为你的目标文件夹路径
target_folder = "F:/迅雷下载/___todo"

# 调用函数压缩exe文件
compress_exe_files(target_folder)
